<template>
    <div>
        <Card shadow>
            <iview-table
                ref="table"
                :baseURL="queryModel.baseURL"
                :menuId="dataModel.menuId"
                :columns="dataModel.columns"
                :order="dataModel.order"
                :pageNumber="pageModel.pageNumber"
                :pageSize="pageModel.pageSize"
                :defaultFilters="queryModel.defaultFilters"
                v-on="{changeTotalSize:changeTotalSize,events:events,changeSelect:changeSelect}">
            </iview-table>
            <br>
            <iview-page 
                :totalSize="pageModel.totalSize"
                :pageNumber="pageModel.pageNumber" 
                :pageSize="pageModel.pageSize"
                :pageSizeOpts="pageModel.pageSizeOpts"
                v-on="{changePageNumber:changePageNumber,changePageSize:changePageSize}">
            </iview-page>
        </Card>
    </div>
</template>

<script>
import iviewTable from '@/view/common/table/Table.vue';
import iviewPage from '@/view/common/page/Page.vue';
export default {
    components: {
        iviewTable,
        iviewPage
    },
    data () {
        return {
            baseURL: '/user/work',
            selectRows: [],
            queryModel: {
                // 网关代理路径(必须)+资源路径(可选)
                baseURL: '/user/work',
                defaultFilters: [
                    {'field': 'submit_user_id', 'value1': this.$store.state.app.loginUser.id, 'operate': '=='}
                ]
            },
            dataModel: {
                menuId: -1,
                columns: [
                    {
                        title: '提交人',
                        key: 'submitUserName'
                    },{
                        title: '要求完成时间',
                        key: 'requireCompleteTime',
                        render: (h, params) => {
                            if (params.row.requireCompleteTime) {
                                return this.$moment(params.row.requireCompleteTime).format('YYYY-MM-DD HH:mm')
                            }
                        }
                    },{
                        title: '处理人',
                        key: 'processUserName'
                    },{
                        title: '受理时间',
                        key: 'acceptTime',
                        render: (h, params) => {
                            if (params.row.acceptTime){
                                return this.$moment(params.row.acceptTime).format('YYYY-MM-DD HH:mm')
                            }
                        }
                    },{
                        title: '答复完成时间',
                        key: 'expectCompleteTime',
                        render: (h, params) => {
                            if (params.row.expectCompleteTime){
                                return this.$moment(params.row.expectCompleteTime).format('YYYY-MM-DD HH:mm')
                            }
                        }
                    },{
                        title: '答复备注',
                        key: 'replyContent'
                    },{
                        title: '实际完成时间',
                        key: 'actualCompleteTime',
                        render: (h, params) => {
                            if (params.row.actualCompleteTime) {
                                return this.$moment(params.row.actualCompleteTime).format('YYYY-MM-DD HH:mm')
                            }
                        }
                    },{
                        title: '审核完成时间',
                        key: 'auditCompleteTime',
                        render: (h, params) => {
                            if (params.row.auditCompleteTime) {
                                return this.$moment(params.row.auditCompleteTime).format('YYYY-MM-DD HH:mm')
                            }
                        }
                    },{
                        title: '状态',
                        key: 'status',
                        render: (h, params) => {
                            let temp = params.row.status
                            if (temp === 0) {
                                temp = '待受理'
                            } else if (temp === 1) {
                                temp = '处理中'
                            } else if (temp === 2) {
                                temp = '已处理'
                            } else if (temp === 3) {
                                temp = '已完成'
                            }
                            return temp
                        }
                    },{
                        title: '完成情况',
                        key: 'timeComplete',
                        render: (h, params) => {
                            let color = ''
                            let temp = params.row.timeComplete
                            if (temp === 0) {
                                temp = '未完成'
                            } else if (temp === 1) {
                                temp = '按时完成'
                                color = 'green'
                            } else if (temp === 2) {
                                temp = '超时完成'
                                color = 'red'
                            }
                            return h('Tag',{
                                props: {
                                    type: 'dot',
                                    color: color
                                }
                            }, temp)
                        }
                    },
                    {
                        title: '操作',
                        width: 150,
                        align: 'center',
                        render: (h, params) => {
                            return h('div', [
                                h('Button', {
                                    props: {
                                        type: 'info',
                                        size: 'default'
                                    },
                                    style: {
                                        marginRight: '5px'
                                    },
                                    on: {
                                        click: () => {
                                            this.auditComplete(params.index, params.row)
                                        }
                                    }
                                }, '审核完成')
                            ]);
                        }
                    }
                ],
                order: 'id desc'
            },
            pageModel: {
                totalSize: 0,
                pageNumber: 1,
                pageSize: 100,
                pageSizeOpts: [10, 50, 100, 500]
            }
        };
    },
    methods: {
        events (item) {
        },
        auditComplete (index, row) {
            if (row.status === 2) {
                let url = '/user/work/auditComplete/' + row.id
                this.$ajax.post(url).then(response => {
                    let {code, msg} = response.data
                    if (code === 0) {
                        this.$bus.alert('success', '操作成功')
                        this.refresh()
                    } else {
                        this.$bus.alert('error', msg)
                    }
                })
            } else {
                this.$bus.alert('warning', '该记录不符合条件')
            }
        },
        refresh () {
            this.$refs.table.refresh()
        },
        changeSelect (rows) {
            this.selectRows = rows
        },
        changeTotalSize (totalSize) {
            this.pageModel.totalSize = totalSize
        },
        changePageNumber (pageNumber) {
            this.pageModel.pageNumber = pageNumber
        },
        changePageSize (pageSize) {
            this.pageModel.pageSize = pageSize
        },
        init () {
            this.refresh()
        }
    },
    mounted () {
        this.init()
    }
}
</script>

<style>

</style>
